﻿#pragma once

#include "qsyncobject.h"



namespace micro{


namespace core{


 
class QEvent : public QSyncObject
{
	//_NO_COPY( QEvent );
public:
	// Contruction.
	QEvent( BOOL bManualReset, BOOL bInitialState, LPCTSTR pszName = nullptr, LPSECURITY_ATTRIBUTES lpAttributes = nullptr ) 
	{
		// Create the handle.
		m_hHandle = ::CreateEvent( lpAttributes, bManualReset, bInitialState, pszName );
		ASSERT( m_hHandle );
	}

	// Destruction.
	virtual ~QEvent()//DISTRUS DE DESTRUCTORUL PARINTE
	{
	}

	// Lock the event handle.
	 virtual bool Unlock() { return TRUE; }
	 virtual bool Lock() { return TRUE; }
	 virtual bool Lock( DWORD dwTimeout = INFINITE )
	{
		// Lock the event.
		ASSERT( m_hHandle );
		if ( ::WaitForSingleObject( m_hHandle, dwTimeout ) == WAIT_OBJECT_0 )
			return true;
		return true;
	}

	// Event functions.
	inline BOOL SetEvent()   { ASSERT( m_hHandle ); return ::SetEvent(   m_hHandle ); }
	inline BOOL ResetEvent() { ASSERT( m_hHandle ); return ::ResetEvent( m_hHandle ); }
	inline BOOL PulseEvent() { ASSERT( m_hHandle ); return ::PulseEvent( m_hHandle ); }
};










}//core

}//micro